﻿@echo off
setlocal enabledelayedexpansion
@REM chcp 65001

@REM 读取文件
@REM 1.设置头文件目录
@REM 先判断文件是存在
SET "INCLUDE_FILE_PATH=config\头文件夹路径.TXT"
IF NOT EXIST %INCLUDE_FILE_PATH% (
    echo 文件不存在：%INCLUDE_FILE_PATH% 无法配置头文件路径!
    exit /b 1
)

@REM 初始化存放内容的变量
SET "INCLUDE_FILE_CONTENT="
for /f "usebackq delims=" %%a in ("%INCLUDE_FILE_PATH%") do (
    set "INCLUDE_FILE_CONTENT=!INCLUDE_FILE_CONTENT! -I "%%a" "
)

@REM 头文件目录输出,后期可删除
echo 头文件路径参数 : %INCLUDE_FILE_CONTENT%


@REM 2.设置库文件目录
@REM 先判断文件是存在
SET "LIB_FILE_PATH=config\库文件夹路径.TXT"
IF NOT EXIST %LIB_FILE_PATH% (
    echo 文件不存在：%LIB_FILE_PATH% 无法配置库文件目录路径!
    exit /b 1
)

@REM 初始化存放内容的变量
SET "LIB_FILE_CONTENT="
for /f "usebackq delims=" %%a in ("%LIB_FILE_PATH%") do (
    set "LIB_FILE_CONTENT=!LIB_FILE_CONTENT! -L "%%a" "
)

ECHO 库文件路径参数 : %LIB_FILE_CONTENT%


@REM 3.设置库文件名称
@REM 先判断文件是存在
SET "LIB_FILENAME=config\库文件名称.TXT"
IF NOT EXIST %LIB_FILENAME% (
    echo 文件不存在：%LIB_FILENAME% 无法配置库文件目录路径!
    exit /b 1
)

@REM 初始化存放内容的变量
SET "LIB_FILENAME_CONTENT="
for /f "usebackq delims=" %%a in ("%LIB_FILENAME%") do (
    set "LIB_FILENAME_CONTENT=!LIB_FILENAME_CONTENT! -l "%%a" "
)


@REM 4.设置公共参数文件名称
@REM 先判断文件是存在
SET "PUBLIC_ARG_FILENAME=config\公共参数.TXT"
IF NOT EXIST %PUBLIC_ARG_FILENAME% (
    echo 文件不存在：%PUBLIC_ARG_FILENAME% 无法配置库文件目录路径!
    exit /b 1
)

@REM 初始化存放内容的变量
SET "PUBLIC_ARG_CONTEXT="
for /f "usebackq delims=" %%a in ("%PUBLIC_ARG_FILENAME%") do (
    set "PUBLIC_ARG_CONTEXT=!PUBLIC_ARG_CONTEXT! %%a "
)



ECHO 库文件名称参数 : %LIB_FILENAME_CONTENT%

ECHO %INCLUDE_FILE_CONTENT% %LIB_FILE_CONTENT% %LIB_FILENAME_CONTENT% %PUBLIC_ARG_CONTEXT% 

g++ %INCLUDE_FILE_CONTENT% %LIB_FILE_CONTENT% %LIB_FILENAME_CONTENT% %PUBLIC_ARG_CONTEXT% main.cpp

pause

